package com.account.service;

import com.account.mapper.AccountMapper;
import com.entity.Account;

import com.entity.Authority;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    AccountMapper accountMapper;


    @Override
    public Account login(Account account) {
        return accountMapper.login(account);
    }

    @Override
    public Account loginByUserName(String username) {
        return accountMapper.loginByUserName(username);
    }

    @Override
    public List<Authority> findAuthoritiesByUsername(String username) {
        return accountMapper.findAuthoritiesByUsername(username);
    }

    @Override
    public List<Account> getAccountList(String username) {
        List<Account> accountList = accountMapper.getAccountList(username);
        return accountList.stream().filter(account -> (username == null || account.getUsername().equals(username))).collect(Collectors.toList());
    }

    @Override
    public int uploadAvatar(Account account) {
        return accountMapper.uploadAvatar(account);
    }


}
